// 路径配置
require.config({
    paths: {
        echarts: '../bgAll/js/dist'
    }
});

// 使用
require(
    [
        'echarts',
        'echarts/chart/radar' // 使用柱状图就加载bar模块，按需加载
    ],
    DrawEChart
);
var myChart;

//创建ECharts图表方法
function DrawEChart(ec) {
    // 基于准备好的dom，初始化echarts图表
    myChart = ec.init(document.getElementById('main'));
    var effect = {
        show: true,
        scaleSize: require('zrender/tool/env').canvasSupported ? 1 : 2,
        period: 60, // 运动周期，无单位，值越大越慢
        color: '#fff',
        shadowColor: 'rgba(220,220,220,0.4)',
        shadowBlur: 5
    };

    function itemStyle(idx) {
        return {
            normal: {
                color: '#fff',
                borderWidth: 1,
                borderColor: ['rgba(30,144,255,1)', 'lime'][idx],
                lineStyle: {
                    //shadowColor : ['rgba(30,144,255,1)','lime'][idx], //默认透明
                    //shadowBlur: 10,
                    //shadowOffsetX: 0,
                    //shadowOffsetY: 0,
                    type: 'solid',
                    shadowBlur: 10
                }
            }
        }
    };
    option = {
        
        polar: [{
            indicator: [{
               text:'',
                max: 40
            }, {
                text:'',
                max: 40
            }, {
                text:'',
                max: 40
            }, {
                text:'',
                max: 40
            }, {
                text:'',
                max: 40
            }, {
                 text:'',
                max: 40
            }],
            name : {
                formatter:'{value}',
                textStyle: {
                    color:'#335683',
                    fontSize: 20
                },

            },
            splitNumber: 4,
            splitArea : {
                show : false
            },
            splitLine : {
                show : true,
                lineStyle : {
                    type: 'dashed',
                    width : 3,
                    color : '#506398'
                }
            },
            axisLine: {            // 坐标轴线
                show: true,        // 默认显示，属性show控制显示与否
                lineStyle: {       // 属性lineStyle控制线条样式
                    color: '#506398',/*'#333f9e','#2ebc9c','#6e46a0',*/
                    width: 2,
                    type: 'solid'
                }
            },
            radius: 125
        }],

        series: [{
            type: 'radar',
            itemStyle:
            {
                normal: {
                    color:'rgba(89,150,240,0.5)',
                    areaStyle: {
                            type: 'default'
                        }

                }
            },
            data: [
                {
                     value: [16,22,40,40,10,28]//设定六象限图默认值   
                },
            ]
        }]
    };
    // 为echarts对象加载数据 
    myChart.setOption(option);
}
(function(){
	var scrollBarLength=6,
		btn1=1,
		btn2=1,
		btn3=0;
	function updateecharts(scrollBarLength,btn1,btn2,btn3){
        /*更新颜色*/
        var total=btn1+btn2+btn3;
        if(total==3){
            myChart._option.series[0].itemStyle.normal.color="rgba(46,188,156,0.5)";
        }else if(total==2){
             myChart._option.series[0].itemStyle.normal.color="rgba(89,150,240,0.5)";
        }else if(total==1){
             myChart._option.series[0].itemStyle.normal.color="rgba(51,63,158,0.5)";
        }else if(total==0){
             myChart._option.series[0].itemStyle.normal.color="rgba(110,70,160,0.5)";
        }
		/*更新数据*/

        myChart._option.series[0].data[0].value=[scrollBarLength*4,10+scrollBarLength+(btn1+btn2+btn3)*4,10+btn1*30,10+btn2*30,10+btn3*30,20+scrollBarLength*2];
        /*更新图*/
        myChart.refresh();
	}

	/*绑定一：拖拽进度条*/
	var $box = $('#box');
    	$bg = $('#bg'),
    	$bgcolor = $('#bgcolor'),
    	$btn = $('#bt'),
    	statu = false,
    	ox = 0,
    	lx = 0,
    	left = 174,
    	bgleft = 0;
    $btn.mousedown(function(e) {
        lx = $btn.offset().left;
        ox = e.pageX - left;
        statu = true;
    });
    $(document).mouseup(function() {
        statu = false;
    });
    $box.mousemove(function(e) {
        if (statu) {
            left = e.pageX - ox;
            if (left < 0) {
                left = 0;
            }
            if (left > 420) {
                left = 420;
            }
            $btn.css('left', left-10);
            $bgcolor.width(left);
            /*保存进度条的值*/
            scrollBarLength = Math.round(parseInt(left / 4.2)/10);
            updateecharts(scrollBarLength,btn1,btn2,btn3);
        }
    });
    
    /*绑定一：点击btn1*/
    $('.btn1').on('click',function(){
    	/*保存btn1值*/
    	btn1=(btn1-1)*(-1);
    	updateecharts(scrollBarLength,btn1,btn2,btn3);
        
    });
    /*绑定二：点击btn2*/
    $('.btn2').on('click',function(){
    	btn2=(btn2-1)*(-1);
    	updateecharts(scrollBarLength,btn1,btn2,btn3);
    });
    /*绑定三：点击btn3*/
    $('.btn3').on('click',function(){
    	btn3=(btn3-1)*(-1);
    	updateecharts(scrollBarLength,btn1,btn2,btn3);
    });
})();

$('.slb-Ctext>div').click(function(){
    var $index=$(this).index();
     $(this).addClass("disabledClass");
    $('.slb-common').eq($index).show();
})

